<?php
/**
 * Created by Veyron
 * User: Vy
 * motto:现在的拼搏 为了更好的明天
 * day:  2020/1/14
 * Time: 15:44
 */
namespace app\admin\controller;
use app\BaseController;
use think\exception\HttpResponseException;

class AdminBase extends BaseController {

    public function initialize(){
        parent::initialize();
    }
    public function isLogin(){
        if(empty(session(config('admin.session_admin')))){
            return false;
        }
        return true;
    }
    public function redirect(...$args){
        throw new HttpResponseException(redirect(...$args));
    }
    /**
     * 修改装状态
     * @return \think\response\Json
     */
    public function status($param = 'status'){

        $param  = input('param.param','status','trim');

        $id     = input('param.id',0,'intval');
        $status = input('param.'.$param,0,'intval');
        //参数
        $data = [
            'id'        => $id,
            $param      => $status
        ];

        $validate = new \app\admin\validate\Status();

        if(!$validate->scene($param)->check($data)){
            return show(config('status.error'),$validate->getError());
        }

        try{
            $controllerName = $this->request->controller();
            $objPath = '\app\common\business\\'. $controllerName;
            $obj = new $objPath();
            $result = $obj->status($id,[$param=>$status]);
        }catch (\Exception $e){
            return show(config('status.error'),'服务器内部错误');
        }
        if($result){
            return show(config('status.success'),'操作成功');
        }
        return show(config('status.error'),'操作失败');
    }

}
